<%@ page import="java.util.List, com.rsscollector.model.CatalogFacade, com.rsscollector.model.vo.Category"%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="/WEB-INF/tlds/app.tld" prefix="app" %>
<html>
<head>
<title>Catalog</title>

<script type="text/javascript">
	dojo.require("dojo.lang.*");
	dojo.require("dojo.widget.*");
	dojo.require("dojo.widget.Tree");
	dojo.require("dojo.widget.TreeSelector");
	dojo.hostenv.writeIncludes();


	dojo.addOnLoad(function() {
		dojo.event.topic.subscribe("nodeSelected",
			 function(message) {
				dojo.byId("selectedNodeTitle").value = message.node.title;
				dojo.byId("selectedNodeId").value = message.node.widgetId;
				if (message.node.parent) dojo.byId("parentSelectedNodeId").value = message.node.parent.widgetId;
			}
		);
	});
</script>
</head>

<body>

<div class="pageheading">Catalog</div>
&nbsp;
<div dojoType="TreeSelector" widgetId="treeSelector" eventNames="select:nodeSelected"></div>

 
<div dojoType="Tree" selector="treeSelector" widgetId="catalog" expandLevel="20">
    <div dojoType="TreeNode" title="ROOT" isFolder="true" widgetId="cat0">
         <app:catalogTree />
    </div>
</div>

<div style="color: red">
    <html:errors/>
</div>

<html:form action="/admin/catalog">

<table>

<tr>
<td>Selected Node</td>
<td><input type="text" readonly="readonly" id="selectedNodeTitle" value=""/>
<html:hidden property="selectedNodeId" styleId="selectedNodeId" value=""/>
<html:hidden property="parentSelectedNodeId" styleId="parentSelectedNodeId" value=""/></td>
</tr>

<tr>
<td>Remove Selected Node</td>
<td><html:submit property="action" value="Remove"/></td>
</tr>

<tr>
<td>Create Child Category</td>
<td><html:text property="newCategory" value=""/> Title: <html:text property="newTitle" value=""/> <html:submit property="action" value="Create Category"/></td>
</tr>

<tr>
<td>Create Child RSS URL</td>
<td><html:text property="newUrl" value=""/> Provider:<html:text property="newUrlProvider" value=""/> <html:submit property="action" value="Create URL"/></td>
</tr>

</table>
</html:form>

<html:form action="/admin/catalog_update">
<%
    List listCate = CatalogFacade.getRootCategories(true);
    if (listCate != null && listCate.size() > 0) {
%>
<table>
     <%
         for (int i = 0; i < listCate.size(); i++) {
             Category obj = (Category) listCate.get(i);
     %>
<tr>
<td>Update Child Category</td>
<td><html:text property="newCategory<%=i%>" value="<%=obj.getName()%>"/> Title: <html:text property="newTitle<%=i%>" value="<%=obj.getTitle()%>"/> </td>
</tr>
    <%}%>
</table>
    <html:submit property="action" value="Update Category"/>
<%
    }
%>
</html:form>

</body>
</html>